package com.proxy.parser.visitor;

import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTableStatusStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
import com.proxy.parser.ParsedResult;
import com.proxy.parser.PoxyVisitor;
import com.proxy.parser.result.ShowCreateTableResult;
import com.proxy.parser.result.ShowTablesResult;

/**
 * Created by liufish on 16/12/27.
 */
public class ShowCreateTableVisitor extends MySqlSchemaStatVisitor implements PoxyVisitor {

    private ShowCreateTableResult  showCreateTableResult;

    public ShowCreateTableVisitor(ParsedResult parsedResult){

        this.showCreateTableResult = (ShowCreateTableResult)parsedResult;
    }


    @Override
    public boolean visit(MySqlShowCreateTableStatement x) {
        boolean superValue = super.visit(x);
        return superValue;
    }

    @Override
    public void endVisit(MySqlShowCreateTableStatement x) {
        super.endVisit(x);
        SQLPropertyExpr expr = (SQLPropertyExpr) x.getName();
        if(expr.getOwner() != null){
            SQLIdentifierExpr owner = (SQLIdentifierExpr)expr.getOwner();
            if(expr.getOwner() != null){
                showCreateTableResult.setProxyDatabase(owner.getName());
            }
        }
    }


}
